<template>
  <div class="visitor-toVisit">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">所属辖区:</div>
        <div class="input-item">
          <a-select ref="select" allowClear v-model="queryParam.policeJurisdictionId" placeholder="请选择所属辖区">
            <a-select-option v-for="(item, index) in policeJurisDictionList" :key="index" :value="item.id">
              {{ item.jurisdictionName }}
            </a-select-option>
          </a-select>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">单位名称:</div>
        <div class="input-item">
          <j-input :maxLength="30" clearable v-model="queryParam.companyMessageName" placeholder="请输入单位名称" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">逾期时间:</div>
        <div class="time-item">
          <start-end-time
            :times="times"
            :showTime="{ format: 'HH:mm:ss' }"
            format="YYYY-MM-DD HH:mm:ss"
            @timeChange="timeChange"
            :resetTime="resetTime"
          ></start-end-time>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">责任民警:</div>
        <div class="input-item">
          <j-input :maxLength="30" clearable v-model="queryParam.policeUserName" placeholder="请输入责任民警" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">检查状态:</div>
        <div class="input-item">
          <a-select ref="select" allowClear v-model="queryParam.eventStatus" placeholder="请选择检查状态">
            <a-select-option value="">全部</a-select-option>
            <a-select-option value="0">未处理</a-select-option>
            <a-select-option value="1">已处理</a-select-option>
          </a-select>
        </div>
      </div>

      <div class="btn-wrap">
        <a-button
          class="searchBtn"
          @click="searchQuery(queryParam.handleEndTime_begin, queryParam.handleEndTime_end)"
          type="primary"
        >
          搜索
        </a-button>
        <a-button class="resetBtn" @click="searchReset()" type="primary"> 重置 </a-button>
      </div>
    </div>

    <div>
      <a-table
        rowKey="id"
        class="tableList"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        @change="handleTableChange"
      >
        <template #event="records">
          <span v-if="records.eventStatus == 1">已处理</span>
          <span v-else>未处理</span>
        </template>
        <template v-slot:action="records">
          <span class="operation deatil-color" v-has="'event:detail'" @click="detailHandle(records)">详情 </span>
        </template>
      </a-table>
    </div>
    <detail-modal ref="detailModal"></detail-modal>
  </div>
</template>
<script>
import moment from 'moment'
import startEndTime from '@/components/startEndTime'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import detailModal from './modules/detailModal'
import { policejurisdictionPage, getPolicejurisdictionList } from '@/api/police'
import JInput from '@/components/jeecg/JInput'
import { mapState } from 'vuex'
export default {
  name: 'visitor-toVisit',
  components: { detailModal, startEndTime, JInput },
  mixins: [JeecgListMixin],
  computed: {
    ...mapState({
      isPoliceAgencyId: (state) => state.user.isPoliceAgencyId,
    }),
  },
  watch: {
    isPoliceAgencyId(v) {
      console.log(v.id, '00000')
      if (v) {
        this.queryParam.policeAgencyId = v.id ? v.id : ''
        this.searchQuery()
        this.getAllJurisdictionPage()
      }
    },
  },
  data() {
    return {
      url: {
        list: '/police/event/page?eventType=1',
        tree: true,
      },
      policeJurisDictionList: [],
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '所属派出所',
          dataIndex: 'policeAgencyName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '所属辖区',
          dataIndex: 'policeJurisdictionName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '单位名称',
          dataIndex: 'companyMessageName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '所属行业',
          dataIndex: 'industryInformationId_dictText',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '责任民警',
          dataIndex: 'policeJurisdictionUserName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '检查逾期时间',
          dataIndex: 'handleEndTime',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '当前检查状态',
          scopedSlots: { customRender: 'event' },
          // dataIndex: 'eventType_dictText',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          align: 'center',
        },
      ],
      disableMixinCreated: true,
    }
  },
  methods: {
    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.handleEndTime_begin = this.$moment(v).valueOf()
      } else {
        this.queryParam.handleEndTime_end = this.$moment(v).valueOf()
      }
      if (v == null) {
        this.queryParam.handleEndTime_begin = null
        this.queryParam.handleEndTime_end = null
      }
    },
    async getAllJurisdictionPage() {
      let data = {
        policeAgencyId: this.queryParam.policeAgencyId,
        pageNo: 1,
        pageSize: 1000,
      }

      let { result } = await getPolicejurisdictionList(data)
      this.policeJurisDictionList = result.records
    },
    detailHandle(records) {
      records.type = 'checkOverdue'
      this.$refs.detailModal.show(records)
    },
  },
}
</script>
